package com.github.niefy.modules.wx.manage;

import com.alibaba.fastjson.JSONObject;
import com.github.niefy.modules.wx.service.ServiceMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/serviceMsg")
public class ServiceMsgController {
    @Autowired
    ServiceMsgService serviceMsgService;

    /**
     * 发送客服消息
     * @param param 包含消息类型（msgType）、目标用户ID（open_id）和主体内容（content）
     * @return
     */
    @PostMapping("/sendServiceMsg")
    public Boolean sendServiceMsg(@RequestBody JSONObject param){
        String msgType = param.getString("msg_type");
        String open_id = param.getString("open_id");
        Object content = msgType.equals("news_link") ? param.getJSONArray("content") : msgType.equals("text") ? param.getString("content") : param.getJSONObject("content");
        return serviceMsgService.sendMsg(msgType,open_id,content);
    }
}
